﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Net.Http.Json;
using System.Net;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
using System.Security.Authentication.ExtendedProtection;
using Newtonsoft.Json.Linq;
using System.Text.Json.Serialization.Metadata;

namespace HttpClientStudy.UnitTest.HttpClients
{
    /// <summary>
    /// HttpClient 常见问题测试
    /// </summary>
    public class HttpClientQuestTest
    {
        private readonly ITestOutputHelper _logger;

        public HttpClientQuestTest(ITestOutputHelper outputHelper)
        {
            _logger = outputHelper;
        }

        [Fact]
        public async Task Multi_ClientObject_Test()
        {
            for (int i = 0; i < 100; i++)
            {
                HttpClient httpClient = new HttpClient();

                var responseMessage = await httpClient.GetAsync(WebApiConfigManager.GetWebApiConfig().BaseUrl + "/api/health");

                responseMessage.EnsureSuccessStatusCode();
            }
        }

        [Fact]
        public async Task Multi_ClientObject2_Test()
        {
            HttpClient httpClient = new HttpClient()
            {
                BaseAddress = new Uri(WebApiConfigManager.GetWebApiConfig().BaseUrl)
            };
            for (int i = 0; i < 100; i++)
            {
                var responseMessage = await httpClient.GetAsync("/api/health");

                responseMessage.EnsureSuccessStatusCode();
            }
        }
    }
}
